package boulderDash;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.util.Timer;

import javax.swing.JFrame;
import javax.swing.JPanel;

	public class BoulderDash extends Canvas{

		static int szerokosc = 1015;
		static int wysokosc = 640;
		
		static Canvas gra;
		
		Plansze plansze = new Plansze();
		RysowaniePlanszy rysowanie = new RysowaniePlanszy();
		KListener k = new KListener();
		
		Image bufor;
		Graphics bg;
		 
		public BoulderDash(){
			
			gra = this;
			this.addKeyListener(k);
			
			JFrame okno = new JFrame("Boulder Dash");
			JPanel panel = (JPanel)okno.getContentPane();
			setBounds(0, 0, szerokosc, wysokosc);
			
			
			panel.setPreferredSize(new Dimension(szerokosc, wysokosc));
			panel.setLayout(null);
			panel.setBackground(Color.BLACK);
			panel.add(this);
			
	
			okno.setBounds(0, 0, szerokosc, wysokosc);
			okno.addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent e){
					System.exit(0);
				}
			});
			
			
			Game game = new Game();
			game.start();
			
			okno.setVisible(true);
			
			
			
			bufor = createImage(szerokosc, wysokosc);
			
			
			bg = bufor.getGraphics();
			
			plansze.zrobPlansze1();
			
		}
		
		public void update(Graphics g){
			
			bg.clearRect(0, 0, szerokosc, wysokosc);
			paint(bg);
			g.drawImage(bufor, 0, 0, gra);
			
			
		}
		
		public void paint(Graphics g){
		
			rysowanie.rysujPlansze(g);
			
		}

		
public static void main(String[] args){
			
			BoulderDash inv = new BoulderDash();
			
		
		}
}
